package com.ikangtai.shecare.common.baseView.pickerDialog.recordPickerDialog;

import android.content.Context;
import android.widget.FrameLayout;
import android.widget.NumberPicker;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.RecordFragmentCommonList;

public class BrandPicker extends FrameLayout {

    private final NumberPicker brandSpinner;
    private int mBrand = 1;
    private OnBrandChangedListener mOnBrandChangedListener;

    public BrandPicker(Context context) {
        super(context);
        /**
         * 加载布局
         */
        inflate(context, R.layout.dialog_brand_record, this);
        /**
         * 初始化控件
         */
        brandSpinner = (NumberPicker) this.findViewById(R.id.brand_picker);
        brandSpinner.setDisplayedValues(RecordFragmentCommonList.recordOvulationPaperBrand);
        brandSpinner.setMaxValue(2);
        brandSpinner.setMinValue(0);
        brandSpinner.setValue(1);
        brandSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
        brandSpinner.clearFocus();
        brandSpinner.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    }

    private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            mBrand = brandSpinner.getValue();
            onTemperatureChanged();
        }
    };

    /*
     *接口回调 参数是当前的View 年月日小时分钟
     */
    public interface OnBrandChangedListener {
        void onTemperatureChanged(BrandPicker view,int minute);
    }
    /*
     *对外的公开方法
     */
    public void setOnBrandChangedListener(OnBrandChangedListener callback) {
        mOnBrandChangedListener = callback;
    }

    private void onTemperatureChanged() {
        if (mOnBrandChangedListener != null) {
            mOnBrandChangedListener.onTemperatureChanged(this, mBrand);
        }
    }
}
